//
//  YJNavigationController.m
//  YJMiGao
//
//  Created by 张龙 on 16/11/4.
//  Copyright © 2016年 张龙. All rights reserved.
//

#import "YJNavigationController.h"

@interface YJNavigationController ()<UINavigationControllerDelegate>
@property(nonatomic,strong)id navideleagte;
@end

@implementation YJNavigationController
- (UIStatusBarStyle)preferredStatusBarStyle{
    
    return UIStatusBarStyleLightContent;
    
}
+ (void)initialize
{
    [UINavigationBar appearance].barTintColor= KBACKNAVIGATIONCOLOR;
    
//    [self.navigationBar setTranslucent:YES];

}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
//    [UINavigationBar appearance].barTintColor= KBACKNAVIGATIONCOLOR;

}
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.navigationBar setTranslucent:NO];

//    self.navigationBar.hidden = YES;
    
    self.navigationController.navigationBar.barTintColor = [UIColor greenColor];
    self.navigationController.navigationBar.backgroundColor = KBACKNAVIGATIONCOLOR;
    [self.navigationBar setTitleTextAttributes:
     @{NSFontAttributeName:[UIFont systemFontOfSize:18],NSForegroundColorAttributeName:[UIColor whiteColor]}];

    
    // Do any additional setup after loading the view.
    self.navideleagte=self.interactivePopGestureRecognizer.delegate;
    self.interactivePopGestureRecognizer.delegate=nil;
    self.delegate=self;
// Do any additional setup after loading the view.
}
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (viewController==self.viewControllers[0]) {
        self.interactivePopGestureRecognizer.delegate=self.navideleagte;
    }
    else
        self.interactivePopGestureRecognizer.delegate=nil;
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.viewControllers.count)
    {
        viewController.hidesBottomBarWhenPushed = YES;
//        [self.navigationBar lt_setBackgroundColor:[KBACKNAVIGATIONCOLOR colorWithAlphaComponent:1]];
//        [UINavigationBar appearance].barTintColor= KBACKNAVIGATIONCOLOR;
        viewController.navigationController.navigationBar.barTintColor=KBACKNAVIGATIONCOLOR;
        viewController.navigationController.navigationBar.titleTextAttributes =  [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
//        [self.navigationController.navigationBar setTitleTextAttributes:
//         @{NSForegroundColorAttributeName:[UIColor whiteColor]}];
        
       viewController.navigationItem.leftBarButtonItem=[UIBarButtonItem rightBarButtonItemWithImage:[UIImage imageNamed:@"img_back"] highlighted:[UIImage imageNamed:@"img_back"] target:self selector:@selector(back)];
       viewController.view.backgroundColor = KBACKGROUNDCOLOR;
    }
    
    [super pushViewController:viewController animated:animated];
}

- (BOOL)shouldAutorotate {
    return NO;
}


- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationPortrait;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)back{
    [self popViewControllerAnimated:YES];
}
@end
